<?php

namespace App\Models\Admin\Message;

class MessageModel extends BaseMessageModel
{
    protected $table = 'message';

    const STATUS_NO  = 0; // 未上架
    const STATUS_YES = 1; // 已上架

    /**
     * 消息总条数
     * @return int
     */
    public function total(): int
    {
        return $this->where('deleted', self::DELETED_NO)
                    ->count();
    }

    /**
     * 消息列表
     * @param array $fields
     * @return array
     */
    public function list(array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
                    ->where('deleted', self::DELETED_NO)
                    ->offset((CURRENT_PAGE - 1) * PAGE_SIZE)
                    ->limit(PAGE_SIZE)
                    ->get()
                    ->toArray();
    }

    /**
     * 消息列表(全部)
     * @param array $fields
     * @return array
     */
    public function releaseList(array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
                    ->where('status', self::STATUS_YES)
                    ->where('deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }

}
